package com.zmn.plat.services.impl.orderconfig.track.reason;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.dto.StatusDTO;
import com.zmn.plat.model.entity.orderconfig.track.reason.OrderTrackReason;
import com.zmn.plat.model.entity.orderconfig.track.reason.OrderTrackReasonQuery;
import com.zmn.plat.persistence.interfaces.orderconfig.track.reason.OrderTrackReasonDao;
import com.zmn.plat.services.interfaces.orderconfig.track.reason.OrderTrackReasonService;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2020/11/19 20:21
 **/
@Service
public class OrderTrackReasonServiceImpl implements OrderTrackReasonService {
    @Resource
    private OrderTrackReasonDao orderTrackReasonDao;

    @Override
    public OrderTrackReason findByKey(Integer id) {
        return orderTrackReasonDao.findByKey(id);
    }

    @Override
    public OrderTrackReason findByReason(String reason) {
        return orderTrackReasonDao.findByReason(reason);
    }

    @Override
    public Integer findMaxSort() {
        return orderTrackReasonDao.findMaxSort();
    }

    @Override
    public List<OrderTrackReason> listByKeys(List<Integer> reasonIds) {
        return orderTrackReasonDao.listByKeys(reasonIds);
    }

    @Override
    public Integer updateSortKey(Integer reasonId, Integer sort, String staffName) {
        OrderTrackReason cancelCategory = new OrderTrackReason();
        cancelCategory.setReasonId(reasonId);
        cancelCategory.setSort(sort);
        cancelCategory.setUpdateTime(new Date());
        cancelCategory.setUpdater(staffName);
        cancelCategory.setUpdateTime(new Date());
        return orderTrackReasonDao.updateSortKey(cancelCategory);
    }

    @Override
    public Integer updateFirstLetterByKey(Integer reasonId, String firstLetter, String staffName) {
        OrderTrackReason cancelCategory = new OrderTrackReason();
        cancelCategory.setReasonId(reasonId);
        cancelCategory.setFirstLetter(firstLetter);
        cancelCategory.setUpdateTime(new Date());
        cancelCategory.setUpdater(staffName);
        return orderTrackReasonDao.updateFirstLetterByKey(cancelCategory);
    }

    @Override
    public Integer updateStatusBatch(List<Integer> categoryIds, Integer status, String staffName) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(categoryIds);
        dto.setStatus(status);
        dto.setUpdater(staffName);
        dto.setUpdateTime(new Date());
        return orderTrackReasonDao.updateStatusBatch(dto);
    }


    @Override
    public List<OrderTrackReason> listPageByQuery(OrderTrackReasonQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return orderTrackReasonDao.listPageByQuery(query);
    }

    @Override
    public List<OrderTrackReason> listByQuery(OrderTrackReasonQuery query) {
        return orderTrackReasonDao.listByQuery(query);
    }

    @Override
    public Integer countByQuery(OrderTrackReasonQuery query) {
        return orderTrackReasonDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(OrderTrackReason orderTrackReason) {
        orderTrackReason.setUpdateTime(new Date());
        return orderTrackReasonDao.updateByKey(orderTrackReason);
    }

    @Override
    public Integer insert(OrderTrackReason orderTrackReason) {
        return orderTrackReasonDao.insert(orderTrackReason);
    }

    @Override
    public Integer deleteByKey(Integer id) {
        return orderTrackReasonDao.deleteByKey(id);
    }

}
